package logic

import (
	"context"
	"month_zg6/rpc/goods"
	"net/http"

	"month_zg6/api/internal/svc"
	"month_zg6/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type TopLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewTopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TopLogic {
	return &TopLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *TopLogic) Top(req *types.TopRequest) (resp *types.Response, err error) {
	top, err := l.svcCtx.Goods.Top(context.Background(), &goods.TopRequest{})
	if err != nil {
		return nil, err
	}
	return &types.Response{
		Code: http.StatusOK,
		Msg:  "排行榜",
		Data: map[string]interface{}{
			"data": top,
		},
	}, err
}
